package com.eastfair.home.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.eastfair.annotation.annotation.log.SysLog;
import com.eastfair.annotation.annotation.security.PreAuth;
import com.eastfair.boot.controller.SuperController;
import com.eastfair.boot.request.PageParams;
import com.eastfair.core.base.R;
import com.eastfair.echo.core.EchoService;
import com.eastfair.home.dto.ExhibitionManageContactModifyDTO;
import com.eastfair.home.dto.ExhibitionManageContactPageQuery;
import com.eastfair.home.dto.ExhibitionManageContactSaveDTO;
import com.eastfair.home.dto.ExhibitionManageContactUpdateDTO;
import com.eastfair.home.entity.ExhibitionManageContact;
import com.eastfair.home.service.ExhibitionManageContactService;
import com.eastfair.home.vo.ExhibitionManageContactVO;
import com.eastfair.home.vo.ExhibitionManageTimingVO;
import io.swagger.annotations.Api;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;


/**
 * <p>
 * 前端控制器
 * 展会联系人
 * </p>
 *
 * @author linan
 * @date 2022-10-22
 */
@Slf4j
@Validated
@RestController
@RequestMapping("/exhibitionManageContact")
@Api(value = "ExhibitionManageContact", tags = "展会联系人")
@PreAuth(replace = "home:exhibitionManageContact:")
public class ExhibitionManageContactController extends SuperController<ExhibitionManageContactService, Long, ExhibitionManageContact, ExhibitionManageContactPageQuery, ExhibitionManageContactSaveDTO, ExhibitionManageContactUpdateDTO> {

    @Autowired
    private EchoService echoService;

    @Override
    public void handlerResult(IPage<ExhibitionManageContact> page) {
        // 想让返回值实现自动回显，请将此行代码打开
        // echoService.action(page);
    }
    /**
     * Excel导入后的操作
     *
     * @param list
     */
    @Override
    public R<Boolean> handlerImport(List<Map<String, String>> list){
        List<ExhibitionManageContact> exhibitionManageContactList = list.stream().map((map) -> {
            ExhibitionManageContact exhibitionManageContact = ExhibitionManageContact.builder().build();
            //TODO 请在这里完成转换
            return exhibitionManageContact;
        }).collect(Collectors.toList());

        return R.success(baseService.saveBatch(exhibitionManageContactList));
    }



    /**
     * 处理参数
     *
     * @param params 分页参数
     */
    @Override
    public void handlerQueryParams(PageParams<ExhibitionManageContactPageQuery> params) {
        ExhibitionManageContactPageQuery pageQuery = params.getModel();

    }

    /**
     * 编辑展会联系人
     * @param params params
     * @return R<Boolean>
     */
    @SysLog("修改展会联系人")
    @PostMapping("/updateExhibitionContact")
    public R<Boolean> updateExhibitionContact(@RequestBody ExhibitionManageContactModifyDTO params){
        return  R.success(baseService.updateExhibitionContact(params));
    }

    /**
     * 查询展会联系人
     * @param params params
     * @return R<Boolean>
     */
    @PostMapping("/queryExhibitionContact")
    public R<List<ExhibitionManageContactVO>> queryExhibitionContact(@RequestBody ExhibitionManageContactPageQuery params){
        return  R.success(baseService.queryExhibitionContact(params));
    }
}
